package ch.ebnoether.gui;

import java.awt.Font;
import java.awt.GridLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import ch.ebnoether.controller.*;
import ch.ebnoether.wuerfel.Dice;

public class WinnerCardRight extends JPanel {

  private static final long serialVersionUID = -829802031343476060L;

  @SuppressWarnings("unused")
  private JLabel dreierPasch;
  @SuppressWarnings("unused")
  private JLabel viererPasch;
  @SuppressWarnings("unused")
  private JLabel fullHouse;
  @SuppressWarnings("unused")
  private JLabel klStrasse;
  @SuppressWarnings("unused")
  private JLabel grStarsse;
  @SuppressWarnings("unused")
  private JLabel yatzy;
  @SuppressWarnings("unused")
  private JLabel chance;
  @SuppressWarnings("unused")
  private JLabel total;
  @SuppressWarnings("unused")
  private JLabel gesamtUnten;
  private JLabel[] labels;

  private JTextField dreierPaschText;
  private JTextField viererPaschText;
  private JTextField fullHouseText;
  private JTextField klStrasseText;
  private JTextField grStarsseText;
  private JTextField yatzyText;
  private JTextField chanceText;
  private JTextField totalText;
  private JTextField gesamtUntenText;
  private JTextField[] textFields;

  private Font schriftLabel;
  private Font schriftTextFeld;

  private Dice[] dices;
  private YatzyGUI yatzi;

  private int totalRechts;
  public static int gesamtTotal;

  public WinnerCardRight(Dice[] dices, YatzyGUI yatzi) {

    this.totalRechts = 0;
    gesamtTotal = 0;
    this.dices = dices;
    this.yatzi = yatzi;
    this.labels = new JLabel[9];
    this.textFields = new JTextField[9];

    this.labels[0] = this.dreierPasch = new JLabel("3er Pasch");
    this.labels[1] = this.viererPasch = new JLabel("4er Pasch");
    this.labels[2] = this.fullHouse = new JLabel("Full House");
    this.labels[3] = this.klStrasse = new JLabel("kl Strasse");
    this.labels[4] = this.grStarsse = new JLabel("gr Strasse");
    this.labels[5] = this.yatzy = new JLabel("Yatzy");
    this.labels[6] = this.chance = new JLabel("Chance");
    this.labels[7] = this.total = new JLabel("Total 2");
    this.labels[8] = this.gesamtUnten = new JLabel("Gesamt");

    this.textFields[0] = this.dreierPaschText = new JTextField();
    this.textFields[1] = this.viererPaschText = new JTextField();
    this.textFields[2] = this.fullHouseText = new JTextField();
    this.textFields[3] = this.klStrasseText = new JTextField();
    this.textFields[4] = this.grStarsseText = new JTextField();
    this.textFields[5] = this.yatzyText = new JTextField();
    this.textFields[6] = this.chanceText = new JTextField();
    this.textFields[7] = this.totalText = new JTextField();
    this.textFields[8] = this.gesamtUntenText = new JTextField();

    this.schriftLabel = new Font("schrift", Font.BOLD, 16);
    this.schriftTextFeld = new Font("schrift", Font.BOLD, 16);

    formatiereFelder();
    erzeugePanel();
    setMouselistener();
  }

  private void formatiereFelder() {

    for (int i = 0; i < this.labels.length; i++) {
      setFormatLabel(this.labels[i]);
      setFormatText(this.textFields[i]);
    }
    this.totalText.setText("" + this.totalRechts);
    this.gesamtUntenText.setText("" + gesamtTotal);
  }

  private void erzeugePanel() {
    this.setLayout(new GridLayout(9, 2, 5, 5));

    for (int i = 0; i < this.labels.length; i++) {
      this.add(this.labels[i]);
      this.add(this.textFields[i]);
    }
  }

  private void setMouselistener() {
    this.dreierPaschText.addMouseListener(new DreierPaschController(this.dices, this, this.yatzi));
    this.viererPaschText.addMouseListener(new VierePaschController(this.dices, this, this.yatzi));
    this.fullHouseText.addMouseListener(new FullHouseController(this.dices, this, this.yatzi));
    this.klStrasseText.addMouseListener(new KleineStrasseController(this.dices, this, this.yatzi));
    this.grStarsseText.addMouseListener(new GrosseStrasseController(this.dices, this, this.yatzi));
    this.yatzyText.addMouseListener(new YatzyController(this.dices, this, this.yatzi));
    this.chanceText.addMouseListener(new ChanceController(this.dices, this, this.yatzi));
  }

  private void setFormatText(JTextField f) {
    f.setEditable(false);
    f.setFont(this.schriftTextFeld);
    f.setHorizontalAlignment(JTextField.CENTER);
  }

  private void setFormatLabel(JLabel l) {
    l.setFont(this.schriftLabel);
  }

  public void aktualisiereTotalRechts() {
    this.totalText.setText("" + this.totalRechts);
    this.gesamtUntenText.setText("" + gesamtTotal);
  }

  public int getTotalRechts() {
    return this.totalRechts;
  }

  public void setTotalRechts(int totalRechts) {
    this.totalRechts = totalRechts;
  }

  public int getGesamtTotal() {
    return gesamtTotal;
  }

  public void setGesamtTotal(int gesamtTotal1) {
    gesamtTotal = gesamtTotal1;
  }
}
